package com.isoft.receiver;

import java.io.InputStream;

import java.net.Socket;
import java.sql.*;

import com.isoft.db.DBConnection;


public class ReceMain {
	static final String IP = "192.168.137.109" ;
	static final int PORT = 9001 ;
	public static void main(String[] args) throws Exception {
		Socket soc=new Socket(IP, PORT);
		InputStream is = soc.getInputStream();
		byte []b=new byte[1024];
		Connection con = DBConnection.getInstance().getConn() ;
		String sql="INSERT INTO boardnum VALUES (UUID(),?,?,?,NOW())";
		PreparedStatement ps=con.prepareStatement(sql);
		
		int t=1;
		while (true) {
			int x=is.read(b);
			String str=new String(b,0,x);
			String num[]=str.split("\\,");
			
			ps.setDouble(1, Double.parseDouble(num[0]));
			ps.setDouble(2, Double.parseDouble(num[1]));
			ps.setDouble(3, Double.parseDouble(num[2]));
			
			ps.addBatch();
			
			if ((t++)>=10) {
				t=1;
				ps.executeBatch();
			}
			System.out.println(Double.parseDouble(num[0])+","+Double.parseDouble(num[1])+","+Double.parseDouble(num[2]));
			
		}
	}

}
